import GCJ_CLASS_TYPE = require('./../../common/GCJ_CLASS_TYPE');
import Point = require('./../../common/graph/Point');
import Serializer = require('./Serializer')
import ObjPosition = require('./ObjPosition')

export  = ObjPositionAlign;
    
    
/**
 *
 * @author 
 *
 */
class ObjPositionAlign extends ObjPosition{
//    public x=0;// 表示对齐点的x，注意不一定是是对象的起点x
//    public y=0;// 表示对齐点的x，注意不一定是是对象的起点x
//    public w=0;// 表示建议的对象的宽
//    public h=0;// 表示建议的对象的高
    
    
    // 对齐点
    /*
    7-----0-----1
    |           |
    6     8     2
    |           |
    5-----4-----3
    * */
    public static ALIGN_POINT_0=0;
    public static ALIGN_POINT_1=1;
    public static ALIGN_POINT_2=2;
    public static ALIGN_POINT_3=3;
    public static ALIGN_POINT_4=4;
    public static ALIGN_POINT_5=5;
    public static ALIGN_POINT_6=6;
    public static ALIGN_POINT_7=7;
    public static ALIGN_POINT_8=8;
    
    public alignType:number = 0; //对齐点
    
    public constructor(x?,y?,w?,h?,an?,at?) {
        super(x,y,w,h,an);
        this.ct=GCJ_CLASS_TYPE.CLASS_TYPE_ObjPositionAlign;
        
        if(at){
            this.alignType=at;
        }
    }
    
    // 拷贝
    public copy(alignPos: ObjPositionAlign) {
        this.constructor(alignPos.x,alignPos.y,alignPos.w,alignPos.h,alignPos.an,alignPos.alignType);
    }
    
    // 根据对齐方式计算本对象的位置
    public toPos():ObjPosition{
        
        var ret: ObjPosition=null;
        switch(this.alignType){
            case ObjPositionAlign.ALIGN_POINT_0:
                ret=new ObjPosition(this.x-this.w/2,this.y,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_1:
                ret=new ObjPosition(this.x-this.w,this.y,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_2:
                ret=new ObjPosition(this.x-this.w,this.y-this.h/2,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_3:
                ret=new ObjPosition(this.x-this.w,this.y-this.h,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_4:
                ret=new ObjPosition(this.x-this.w/2,this.y-this.h,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_5:
                ret=new ObjPosition(this.x,this.y-this.h,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_6:
                ret=new ObjPosition(this.x,this.y-this.h/2,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_7:
                ret=new ObjPosition(this.x,this.y,this.w,this.h);
                break;

            case ObjPositionAlign.ALIGN_POINT_8:
                ret=new ObjPosition(this.x-this.w/2,this.y-this.h/2,this.w,this.h);
                break;
        }
        
        return ret;
    }
    
    // 从json对象(注意不是json字符串)中解析
    public fromJson(jsonObj,versionId) {
        super.fromJson(jsonObj,versionId);

        this.alignType=jsonObj.alignType;
        
    }
    // 转成json字符串
    public toJson(): string {
        // 去掉父json字符串的头尾
        var superJson=super.toJson();
        superJson=superJson.substr(1,superJson.length-2);

        var ret='{';
        ret+=superJson;
                                                                                
        // alignType
        ret+=',';
        ret+='"alignType":';
        ret+=this.alignType;

        ret+='}';
        return ret;
    }  
       
//SJG_MARK_APPEND--------------------


}//SJG_MARK_END-------------------------